package com.example.tbplus14.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;

import java.io.IOException;

@Getter
@AllArgsConstructor
public enum InspectionHazardEnum {

    ALL_COUNT("allCount","漏洞总数%s个", 0, 0, 0),
    SERIOUS("seriousVulnerabilities", "严重漏洞%s个", 178,34,34),
    HIGH("highRiskVulnerabilities", "高危漏洞%s个", 255, 0, 0),
    MEDIUM("mediumRiskVulnerabilities", "中危漏洞%s个", 218,165,32),
    LOW("lowRiskVulnerabilities", "低危漏洞%s个", 50,205,50),
    COMPANY("company", "因此对%s产品全生命周期研发管理系统整体安全风险评级为", 0,0,0),
    RATING("rating","%s", 205,92,92);

    public static String desc(String value){
        for (InspectionHazardEnum inspectionHazardEnum : InspectionHazardEnum.values()) {
            if (inspectionHazardEnum.getValue().equals(value)){
                return inspectionHazardEnum.desc;
            }
        }
        throw new RuntimeException("巡检漏洞类型异常");
    }

    public static void setColor(String value, PDPageContentStream contentStream) throws IOException {
        if (null == value){
            contentStream.setNonStrokingColor(0, 0, 0);
            return;
        }
        for (InspectionHazardEnum inspectionHazardEnum : InspectionHazardEnum.values()) {
            if (inspectionHazardEnum.getValue().equals(value)){
                contentStream.setNonStrokingColor(inspectionHazardEnum.getR(), inspectionHazardEnum.getG()
                        , inspectionHazardEnum.getB());
                break;
            }
        }
    }

    private String value;
    private String desc;
    private int r;
    private int g;
    private int b;

}
